!(function () {
    $(".send").hide();
    $('#sendNick').on('click',function(){
        $(".nick").hide();
        $(".send").show();        
        let nickName = $("#nickname").val();
        var client = io('http://localhost:3000/', {
            reconnectionAttempts: 3, //重连次数
            reconnection: true, //是否重连
            reconnectionDelay: 1000,
            reconnectionDelayMax: 5000,
            timeout: 2000, //超时时间
            autoConnect: true //自动连接
        });
        
        client.on('connect', function () {
            $("#send").on('click', function () {
                var text = $('#content').val();
                client.emit('server.message',text);
            });
            //告诉服务器我上线了，我的昵称是这个            
            client.emit('server.online', nickName);
    
            //服务器收到你上线，告诉你你上线成功了  
            client.on('client.online', function (msg) {
                console.log('服务器说我在线了', msg);
            });
            client.on('client.message', function (msg) {
                console.log('服务器回的消息', msg);
            });


            $(document).on('paste',function(e){
                console.log(e);
                var originalEvent =  e.originalEvent;
                var items = originalEvent.clipboardData.items;
                console.log("items:",items);
                if(items && items.length >0){
                    e.preventDefault();
                    items = Array.from(items);
                    items.forEach(item => {
                        console.log("item kind:",item);
                        if(item.kind == 'string'){
                            console.log(item);
                        }
                        if(item.kind == 'file'){
                            console.log("有文件")
                            var pastFile = item.getAsFile();
                            debugger
                            var reader = new FileReader();
                            reader.onloadend = function(){
                                var result = reader.result;
                                console.log(result);
                            }
                            reader.readAsDataURL(pastFile);
                        }
                    });
                }
            });

            
        });

        client.on('error', function (err) {
            console.log(err);
        });
        client.on('disconnect', function (err) {
            console.log('disconnect', err);
        });
        client.on('reconnect', function (count) {
            console.log('reconnect', count);
        });
        client.on('reconnect_attempt', function (count) {
            console.log('reconnect_attempt', count);
        });
        client.on('reconnecting', function (count) {
            console.log('reconnecting', count);
        });
        client.on('reconnect_error', function (err) {
            console.log('reconnect_error', err);
        });
        client.on('reconnect_failed', function () {
            console.log('reconnect_failed');
        });
    });

   
})()